package com.design.facade;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * @author leali
 * @title: FileReader
 * @projectName design
 * @description: FileReader：文件读取类，充当子系统类
 * @date 2022/1/2 23:50
 */
public class FileReader {
    public String read(String fileNameSrc) {
        System.out.println("读取文件，获取明文：");
        Path path = Paths.get(fileNameSrc);
        StringBuilder stringBuilder = new StringBuilder();
        try (BufferedReader reader = Files.newBufferedReader(path)) {
            int data;
            while ((data = reader.read()) != -1) {
                stringBuilder.append((char) data);
            }
            System.out.println(stringBuilder);
        } catch (FileNotFoundException e) {
            System.out.println("文件不存在！");
        } catch (IOException e) {
            System.out.println("文件操作错误！");
        }
        return stringBuilder.toString();
    }
}
